package com.ljwy.daka.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.ljwy.daka.R;
import com.ljwy.daka.info.DaKaInfo;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ClockAdapter extends BaseViewAdapter<DaKaInfo.DataBeanX.DataBean> {
    private static final int TIME = 10 * 1000;

    public ClockAdapter(Context context, List<DaKaInfo.DataBeanX.DataBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(context, R.layout.adapter_clock, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        DaKaInfo.DataBeanX.DataBean info = list.get(i);
        holder.cpNameTv.setText(TextUtils.isEmpty(info.getCp_name()) ? "-" : info.getCp_name());
        holder.noTv.setText(info.getNo());
        holder.whenTv.setText(info.getWhen());
        holder.passTv.setText(info.isPass() ? "上传成功" : "上传失败");
        holder.passTv.setTextColor(!info.isPass() ? context.getColor(R.color.red) : context.getColor(R.color.colorAccent));
        if (i == 0) {
            setTextSize(holder, 20);
            holder.cpNameTv.postDelayed(new Runnable() {
                @Override
                public void run() {
                    setTextSize(holder, 16);
                }
            }, TIME);
        } else {
            setTextSize(holder, 16);
        }
        return view;
    }

    private void setTextSize(ViewHolder holder, int i) {
        holder.cpNameTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, i);
        holder.noTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, i);
        holder.whenTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, i);
        holder.passTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, i);
    }

    static
    class ViewHolder {
        @BindView(R.id.no_tv)
        TextView noTv;
        @BindView(R.id.cp_name_tv)
        TextView cpNameTv;
        @BindView(R.id.when_tv)
        TextView whenTv;
        @BindView(R.id.pass_tv)
        TextView passTv;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
